package com.googlecode.cswish.test.mock.struts2;

import java.util.HashMap;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.CompoundRoot;
import com.opensymphony.xwork2.util.ValueStack;

public class MockValueStack implements ValueStack{

	private Map<String, Object> context = new HashMap<String, Object>();
	private CompoundRoot root = new CompoundRoot();
	
	private Map<String, Object> action = new HashMap<String, Object>();
	
	public MockValueStack(Container container) {
		root.push(action);
		if (container != null) {
			context.put(ActionContext.CONTAINER, container);
		}
	}
	
	@Override
	public Map<String, Object> getContext() {
		return context;
	}

	@Override
	public void setDefaultType(Class defaultType) {
		
	}

	@Override
	public void setExprOverrides(Map<Object, Object> overrides) {
		
	}

	@Override
	public Map<Object, Object> getExprOverrides() {
		return null;
	}

	@Override
	public CompoundRoot getRoot() {
		return root;
	}

	@Override
	public void setValue(String expr, Object value) {
		action.put(expr, value);
	}

	@Override
	public void setParameter(String expr, Object value) {
		
	}

	@Override
	public void setValue(String expr, Object value,
			boolean throwExceptionOnFailure) {
		action.put(expr, value);
	}

	@Override
	public String findString(String expr) {
		Object val = action.get(expr);
		return val == null ? null : val.toString();
	}

	@Override
	public String findString(String expr, boolean throwExceptionOnFailure) {
		return findString(expr);
	}

	@Override
	public Object findValue(String expr) {
		return action.get(expr);
	}

	@Override
	public Object findValue(String expr, boolean throwExceptionOnFailure) {
		return action.get(expr);
	}

	@Override
	public Object findValue(String expr, Class asType) {
		return action.get(expr);
	}

	@Override
	public Object findValue(String expr, Class asType,
			boolean throwExceptionOnFailure) {
		return action.get(expr);
	}

	@Override
	public Object peek() {
		return root.peek();
	}

	@Override
	public Object pop() {
		return root.pop();
	}

	@Override
	public void push(Object o) {
		root.push(o);
	}

	@Override
	public void set(String key, Object o) {
		action.put(key, o);
	}

	@Override
	public int size() {
		return root.size();
	}

}
